namespace Agile.Genie.Descriptors
{
    /// <summary>
    /// Singleton class used to cache the vs project file collection 
    /// </summary>
    public class VisualStudioProjectFileCache
    {
        /// <summary>
        /// Cached copy of loaded tables
        /// </summary>
        private static readonly VisualStudioProjectFileCollection _loadedVisualStudioProjectFiles =
            VisualStudioProjectFileCollection.Build();

        private static readonly object padlock = new object();

        /// <summary>
        /// The unique instance of the visual studio project file collection.
        /// </summary>
        private static volatile VisualStudioProjectFileCache _uniqueInstance;

        /// <summary>
        /// Constructor
        /// </summary>
        private VisualStudioProjectFileCache()
        {
        }

        /// <summary>
        /// Gets the collection of projects that have already been loaded.
        /// </summary>
        public VisualStudioProjectFileCollection LoadedProjectFiles
        {
            get { return _loadedVisualStudioProjectFiles; }
        }

        /// <summary>
        /// Get the instance of the collecion
        /// </summary>
        /// <returns></returns>
        public static VisualStudioProjectFileCache GetInstance()
        {
            if (_uniqueInstance == null)
            {
                lock (padlock)
                {
                    if (_uniqueInstance == null)
                        _uniqueInstance = new VisualStudioProjectFileCache();
                }
            }
            return _uniqueInstance;
        }
    }
}